#include "app_porting.h"

int32_t console_init(void)
{	
	uart_receive_clear(CONSOLE_DEVICE);	
	return LS_SUCCESS;
}
static void help(void)
{
#ifdef LIB_PRINTF_SUPPORT
	printf("SoftwareVersion=%d,Date=%s,Time=%s\r\n",SOFTWARE_VERSION,__DATE__,__TIME__);
	printf("help or <cr>:\r\n\tshow this help.\r\n");
	printf("reset:\r\n\treboot system.\r\n");
	printf("\r\n\r\n");
#endif		
}

void console_task(void *pdata)
{
	uint8_t cmd[200];
	uint8_t len;
	
	pdata  = pdata;   	
#ifdef LIB_PRINTF_SUPPORT
	printf("[%s](%d) task created.\r\n",__FUNCTION__,__LINE__);
#endif		
	while(1)
	{
		memset(cmd,0,sizeof(cmd));
		len=uart_get_str(CONSOLE_DEVICE,cmd,sizeof(cmd));
		if(0==len){
			help();
			continue;
		}
		if(0==strcmp((const char*)cmd,"help")){
			help();	
		}else if(0==strcmp((const char*)cmd,"reset")){
			reboot_system();
		}else{
			help();
		}
	}
}
